<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-theme.min.css">
<script src="${pageContext.request.contextPath}/js/jquery-1.11.1.js"></script>
<script
	src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript">
function checkForm(){
	var search_value=$("#search_value").val();;
    if(search_value == ""){
		alert("请填入要查找的数据库/表/字段名");
		return false;
	}
	return true;
};
function changetable(){
	var parsent = document.getElementsByTagName("tr");
	var child  = new Array(4);
	 child[0] = document.createElement("td");
	 child[1] = document.createElement("td");
	 child[2] = document.createElement("td");
	 child[3] = document.createElement("td");
	var note = document.createt createTextNode("none");
	for(var i = 1;i<4;i++){
		child[i].appendChild(note);
		parsent.appendChild(child[i]);
	}
	
}
</script>
<title>数据管理2</title>
</head>
<body>
	<!-- 创建两个数据库，表的对象，用于相关方法的调用 -->
	<jsp:useBean id="database" scope="page" class="dao.DataBaseDao"></jsp:useBean>
	<jsp:useBean id="table" scope="page" class="dao.TableDao"></jsp:useBean>
	<nav class="navbar navbar-inverse navbar-fixed-top">
	<div class="container">
		<div class="navbar-header">
			<a class="navbar-brand" href="Javascript: void(0)"><strong
				class="h3">数据管理&nbsp;&nbsp;</strong></a>
		</div>
		<div class="collapse navbar-collapse">
			<ul class="nav navbar-nav">
				<li id="dbs"><a href="DataBaseServlet?method=getDBList"
					id="show_dbs"><i class="glyphicon glyphicon-list">&nbsp;</i>数据库&nbsp;</a></li>
				<li id="tables"><a href="DataBaseServlet?method=getTableList"><i
						class="glyphicon glyphicon-list">&nbsp;</i>表&nbsp;</a></li>
				<li id="fields"><a href="DataBaseServlet?method=getFieldList"><i
						class="glyphicon glyphicon-list"></i>&nbsp;字段</a></li>
			</ul>
			<form name="search" class="navbar-form pull-right" method="post"
				action="DataBaseServlet?method=search"
				onsubmit="script:return checkForm()">
				<div class="col-sm-4">
					<select class="form-control" id="search_from" name="search_from">
						<option value="search_db">数据库</option>
						<option value="search_table">表</option>
						<option value="search_field">字段</option>
					</select>
				</div>
				<input class="span2" id="search_value" name="search_value"
					type="text" style="height: 35px;" placeholder="请输入">
				<button type="submit" class="btn">
					<i class="icon-search"></i>&nbsp;搜索
				</button>
			</form>
		</div>
	</div>
	</nav>
	<div class="container"
		style="position: relative; top: 100px; left: 100px">
		<div class="row-fluid">
			<div class="col-lg-9">
				<c:if test="${!empty searchResult }">
					<legend>搜索结果如下</legend>
				</c:if>
			</div>
		</div>

		<!--显示数据库信息 -->
		<div class="row-fluid">
			<div class="col-lg-9">
				<c:if test="${! empty dbList}">
					<legend>数据库：</legend>
					<table class="table table-bordered table-hover">
						<tr>
							<th>数据库名</th>
							<th>登录名</th>
							<th>密码</th>
							<th>url</th>
							<th width="20%">操作</th>
						</tr>
						<c:forEach var="db" items="${dbList }">
							<tr>
								<td><span>&nbsp;${db.dbName }</span></td>
								<td><span>&nbsp;${db.userName }</span></td>
								<td><span>&nbsp;${db.password }</span></td>
								<td><span>&nbsp;${db.url }</span></td>
								<td><c:if test="${empty searchResult }">
										<input type="button" class="btn btn-primary"
											onclick="javascript:window.location='DataBaseServlet?method=deleteDB&Id=${db.id}'"
											value="删除" />
									</c:if> <c:if test="${!empty searchResult }">
										<input type="button" class="btn btn-primary"
											onclick="javascript:window.location='DataBaseServlet?method=deleteDB&Id=${db.id}&searchName=${searchName}'"
											value="删除" />
									</c:if> <input type="button" class="btn btn-primary"
									onclick="javascript:window.location='DataBaseServlet?method=manageDB&Id=${db.id}'"
									value="管理" /></td>
							</tr>
						</c:forEach>
					</table>
				</c:if>
			</div>
		</div>

		<!-- 显示表信息-->
		<div class="row-fluid">
			<div class="col-lg-9">
				<c:if test="${ !empty showDBname }">
					<legend>数据库——${showDBname }&nbsp;表管理</legend>
				</c:if>
				<c:if test="${! empty tableList}">
					<c:if test="${empty showDBname }">
						<legend>表：</legend>
					</c:if>

					<table class="table table-bordered table-hover ">
						<tr>
							<th>数据库</th>
							<th>表名</th>
							<th width="20%">操作</th>
						</tr>
						<c:forEach var="table" items="${tableList }">
							<tr>
								<td><span>&nbsp;${database.getDBname(table.dbId)}</span></td>
								<td><span>&nbsp;${table.tableName }</span></td>
								<td><c:if test="${ !empty showDBname }">
										<input type="button" class="btn btn-primary"
											onclick="javascript:window.location='DataBaseServlet?method=deleteTable&Id=${table.id}&dbId=${dbId}'"
											value="删除" />
									</c:if> <c:if test="${ empty showDBname }">
										<c:if test="${!empty searchName }">
											<input type="button" class="btn btn-primary"
												onclick="javascript:window.location='DataBaseServlet?method=deleteTable&Id=${table.id}&searchName=${searchName}'"
												value="删除" />
										</c:if>
										<c:if test="${empty searchName }">
											<input type="button" class="btn btn-primary"
												onclick="javascript:window.location='DataBaseServlet?method=deleteTable&Id=${table.id}'"
												value="删除" />
										</c:if>
									</c:if> <input type="button" class="btn btn-primary"
									onclick="javascript:window.location='DataBaseServlet?method=manageTable&Id=${table.id}'"
									value="管理" /></td>
							</tr>
						</c:forEach>
					</table>
				</c:if>
			</div>
		</div>

		<!-- 显示字段信息-->
		<div class="row-fluid">
			<div class="col-lg-9">
				<c:if test="${ !empty showTablename }">
					<legend>表——${showTablename }&nbsp;字段管理</legend>
				</c:if>
				<c:if test="${! empty fieldList}">
					<c:if test="${empty showTablename }">
						<legend>字段：</legend>
					</c:if>
					<table class="table table-bordered table-hover">
						<tr>
							<th>数据库</th>
							<th>表</th>
							<th>字段</th>

							<th width="20%">操作</th>
						</tr>
						<c:forEach var="field" items="${fieldList }">
							<tr>
								<td><span>&nbsp;${database.getDBname(table.getdbId(field.tId)) }</span></td>
								<td><span>&nbsp;${table.getTablename(field.tId) }</span></td>
								<td><span>&nbsp;${field.fieldName }</span></td>

								<td><c:if test="${!empty showTablename }">
										<input type="button" class="btn btn-primary"
											onclick="javascript:window.location='DataBaseServlet?method=deleteField&Id=${field.id}&tableId=${tableId}'"
											value="删除" />
									</c:if> <c:if test="${empty showTablename }">

										<c:if test="${empty searchName }">
											<input type="button" class="btn btn-primary"
												onclick="javascript:window.location='DataBaseServlet?method=deleteField&Id=${field.id}'"
												value="删除" />
										</c:if>
										<c:if test="${!empty searchName }">
											<input type="button" class="btn btn-primary"
												onclick="javascript:window.location='DataBaseServlet?method=deleteField&Id=${field.id}&searchName=${searchName}'"
												value="删除" />
										</c:if>
									</c:if></td>
							</tr>

						</c:forEach>
					</table>
				</c:if>
			</div>
		</div>

		<!-- 显示页面初始信息 
<div class="row-fluid">
			<div class="col-lg-9">
			<c:if test="${ empty searchResult }">
				<c:if test="${ empty dbList}">
				<c:if test="${ empty tableList}">
				<c:if test="${ empty fieldList}">
				<c:if test="${ empty showTablename }">
				<c:if test="${ empty showDBname }">
				<script type="text/javascript">
				document.getElementById("show_dbs").click();
				</script>
				</c:if>
				</c:if>
				</c:if>
				</c:if>
				</c:if>
				</c:if>
				</div>
				</div>
				-->
		<!-- 返回失败信息 -->

		<c:if test="${! empty fail }">
			<script type="text/javascript">
				alert("删除失败");
			</script>
		</c:if>
		<c:if test="${! empty succeed }">
			<script type="text/javascript">
				alert("删除成功");
			</script>
		</c:if>
	</div>

</body>

</html>